package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.masks.Pixelmask;
	/**
	 * ...
	 * @author Donatello
	 */
	public class HallGuy extends Entity
	{
		[Embed(source = "img/sheets/hallGuy.png")] private const PLAYER_ANIM:Class;
		[Embed(source = "img/sheets/hallGuyCell.png")] private const PLAYER_PIX:Class;
		private var playerAnim:Spritemap;
		
		private var pressed:Boolean = false;
		public var state:String = "idle";
		private var time:Number = 0.0;
		private var llave:Boolean = false;
		private var limit:Number;
		private var limitTime:Number;
		private var texto:Boolean = false;
		
		public function HallGuy(px:Number=305,py:Number=500) 
		{
			
			playerAnim = new Spritemap(PLAYER_ANIM, 54,147);
			
			playerAnim.add("idle", [0], 10, true);
			playerAnim.add("walking", [1,2,3,4], 10, true);
			playerAnim.add("hand", [5, 6, 7], 10, false);
			playerAnim.add("watch", [8], 10, false);
			
			graphic = playerAnim;
			playerAnim.flipped = true;
			
			mask = new Pixelmask(PLAYER_PIX);
			type = "HallGuy";
			
			x = px;
			y = py;
			limit = x - 66;
			
			limitTime = x / 100;
			
			playerAnim.play("idle");
			
		}
		
		override public function update():void
		{
			time += FP.elapsed;
			
			if (state != "watch")
			{
				if (time >= limitTime && !llave)
				{
					state = "hand";
					playerAnim.play("hand");
					time = 0.0;
				}
				if (time>=1 && llave)
				{
					if(!texto)
					{
						if (FP.rand(2) == 1)
							FP.world.add(new Dialog("Bien, gracias Henry", x, y, 2, y - 50));
						else
							FP.world.add(new Dialog("Hola Henry", x, y, 2, y - 50));
						texto = true;
					}
					
					state = "walking";
					playerAnim.play("walking");
				}
			}
			if (state == "walking")
			{
				
				x -= 1;
				y -= 2;
			}
			
			if (x <= limit)
			{
				state = "watch";
				playerAnim.play(state);
			}
			
			
		}
		
		public function caminar():void
		{
			if(!llave)
			{	
				llave = true;
				time = 0.0;
			}
		}
	}

}